package com.lg.utils.hutool.url;

import cn.hutool.core.lang.Console;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.util.CharsetUtil;

public class UrlBuilderTest {
    public static void main(String[] args) {
        String buildUrl = UrlBuilder.create().setHost("www.hutool.cn").build();
        // http://www.hutool.cn/
        System.out.println( buildUrl);


        String buildUrl2 = UrlBuilder.create()
                .setScheme("https")
                .setHost("www.hutool.cn")
                .addPath("/aaa").addPath("bbb")
                .addQuery("ie", "UTF-8")
                .addQuery("wd", "中文")
                .build();
        // https://www.hutool.cn/aaa/bbb?ie=UTF-8&wd=%E4%B8%AD%E6%96%87
        System.out.println(buildUrl2);

        String buildUrl3 = UrlBuilder.create()
                .setScheme("https")
                .setHost("www.hutool.cn")
                .setPort(8088)
                .addPath("/aaa").addPath("bbb")
                .addQuery("ie", "UTF-8")
                .addQuery("wd", "中文")
                .build();
        // https://www.hutool.cn:8088/aaa/bbb?ie=UTF-8&wd=%E4%B8%AD%E6%96%87
        System.out.println(buildUrl3);

        //of  =  解析
        UrlBuilder builder = UrlBuilder.ofHttp
                ("www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1", CharsetUtil.CHARSET_UTF_8);

        // 输出张三     未编码的
        Console.log(builder.getQuery().get("a"));
        // 输出李四     编码过的
        Console.log(builder.getQuery().get("b"));
        // null
        Console.log(builder.getQuery().get("bb"));


    }
}
